﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace PlainOldVersionControl.Data
{
    public class Tx : IDisposable
    {
        public static Tx Start()
        {
            return new Tx();
        }

        public Tx()
        {
            DA.Begin();
        }

        #region IDisposable Members

        public void Dispose()
        {
            if (Marshal.GetExceptionCode() == 0)
            {
                try
                {
                    DA.Commit();
                }
                catch (Exception ex)
                {
                    DA.RollBack();
                    throw new Exception(ex.Message, ex);
                }
            }
            else
                DA.RollBack();
        }

        #endregion
    }
}
